home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / pleas / ole / excel / solver.txt < prev    next >
Encoding:
Text File  |  1994-06-10  |  777 b   |  22 lines

  1. Dim APPXL As object
  2. Dim XL As object
  3. Dim ws As object
  4.  
  5. Set APPXL = GetObject(, "Excel.Application")
  6. Set XL = APPXL.Application
  7. XL.Workbooks.Open "C:\WINDOWS\EXCEL\EXAMPLES\SOLVER\SOLVEREX.XLS"
  8.  
  9. Set ws = XL.ActiveSheet
  10. oldP$ = ws.Range("$F$14").Value
  11. XL.ExecuteExcel4Macro "[SOLVER.XLA]SOLVER!SOLVER.OK(!R10C6,1,0,)"
  12. XL.ExecuteExcel4Macro "[SOLVER.XLA]SOLVER!SOLVER.ADD(!R10C6,1,""=40000"")"
  13. XL.ExecuteExcel4Macro "[SOLVER.XLA]SOLVER!SOLVER.OK(!R14C6,1,0,(!R10C2:R10C5))"
  14. XL.ExecuteExcel4Macro "[SOLVER.XLA]SOLVER!SOLVER.SOLVE(True)"
  15. newP$ = ws.Range("$F$14").Value
  16. MsgBox "Old: " & Format(oldP$, "currency") & Chr$(10) & "New: " & Format(newP$, "currency"), , "Profit"
  17. XL.Workbooks(1).[Close] (False)
  18.  
  19. Set ws = Nothing
  20. Set XL = Nothing
  21. Set APPXL = Nothing
  22.